package com.uroad.lib.widget.photopicker.headpic;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;

import com.uroad.lib.R;
import com.uroad.lib.widget.dialog.DialogHelper;
import com.uroad.lib.widget.photopicker.PhotoPickUtils;
import com.uroad.lib.widget.photopicker.widget.Titlebar;


public class HeadpicActivity extends AppCompatActivity {
    private ClipImageLayout mClipImageLayout;
    Titlebar titlebar;
    String url;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_headpic);
        url = getIntent().getStringExtra("url");
        mClipImageLayout = (ClipImageLayout) findViewById(R.id.id_clipImageLayout);
        if (!TextUtils.isEmpty(url)) {
            mClipImageLayout.setImageDrawable(url);
        }
        titlebar = (Titlebar) findViewById(R.id.titlebar);
        titlebar.init(this);
        titlebar.getTvRight().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try{
                    PhotoPickUtils.headPic = mClipImageLayout.clip();
                    Intent intent = new Intent();
                    setResult(RESULT_OK, intent);
                    finish();
                }catch (Exception e){
                    DialogHelper.showShortTost(HeadpicActivity.this,"此照片不符合规格，请选择其他照片");
                }
            }
        });
    }
}
